/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelInfo.java
 *
 * Created on 30/07/2010, 09:55:04
 */

package gui;

import graphic.ARPGanttRenderer;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.text.SimpleDateFormat;
import java.util.Date;
import main.entities.AirlineNetwork;
import main.entities.Flight;

/**
 *
 * @author alexanderdealmeidapinto
 */
public class JPanelFlightInfo extends javax.swing.JPanel {
    private Flight flight;
    private Long minToMili = 60*1000l;
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
    private AirlineNetwork airlineNetword;

    //JPanel size = 187, 86
    /** Creates new form JPanelInfo */
    public JPanelFlightInfo() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 187, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 91, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    public void setInfo(Flight flight, AirlineNetwork airlineNetwork){
        if(this.flight != flight){
//            System.out.println("Repintando");
            this.flight = flight;
            this.airlineNetword = airlineNetwork;
            repaint();
        }
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        Rectangle2D bar = new Rectangle2D.Double(45.0, 10.0, 100.0, 30.0);
        ARPGanttRenderer.drawFlight((Graphics2D) g,bar, 30, true, true, true, flight);

        long baseTime = airlineNetword.getAirlineGraphicConfigs().getBaseTime();
        long beginTime = baseTime + (flight.getRealDepartureTime() - flight.getGroundTime())*minToMili;
        long endTime = baseTime + (flight.getRealArrivalTime())*minToMili;

        g.setFont(airlineNetword.getAirlineGraphicConfigs().getReduzedFont());
        g.drawString(simpleDateFormat.format(new Date(beginTime)), (int) bar.getMinX() - 40,(int)(bar.getMaxY() + 20));
        g.drawString(simpleDateFormat.format(new Date(endTime)), (int) bar.getMaxX() - 40,(int)(bar.getMaxY() + 20));

        g.drawString(String.format("%-7s [%d]", "Tempo de Voo", flight.getFlightTime()), (int) bar.getMinX() - 40,(int)(bar.getMaxY() + 30));
        g.drawString(String.format("%-7s [%d]", "Tempo de Solo", flight.getGroundTime()), (int) bar.getMinX() - 40,(int)(bar.getMaxY() + 40));
        g.drawString(String.format("%-7s [%d]", "Indice", flight.getNumber()), (int) bar.getMaxX() - 40,(int)(bar.getMaxY() + 40));
        if(flight.getDelay() != 0) g.drawString(String.format("%-7s [%+d]", "Atraso", flight.getDelay()), (int) bar.getMaxX() - 40,(int)(bar.getMaxY() + 30));

    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
